odoo.define('web_optimize.PreviewHelper', function (require) {
"use strict";

var core = require('web.core');
// var ServicesMixin = require('web.ServicesMixin');
var rpc = require('web.rpc');


var PreviewDialog = require('web_optimize.PreviewDialog');

var PreviewHelper = core.Class.extend({
	createAttachmentPreview: function(id) {
		rpc.query({
			"model": "ir.attachment",
			"method": "search_read",
			"params": {
				"fields": ['name', 'url', 'type', 'mimetype', 'extension'],
				"domain": [['id', '=', id]]
			},

		}).then(function(attachments) {
			var attachment = attachments[0];
			if(!attachment.url && attachment.type === "binary") {
				attachment.url = '/web/content/' + attachment.id + '?download=true';
			}
			PreviewDialog.createPreviewDialog(self, attachment.url, attachment.mimetype,
					attachment.extension, attachment.name);
		});
	}
});

PreviewHelper.createAttachmentPreview = function(id) {
    return new PreviewHelper().createAttachmentPreview(id);
};

return PreviewHelper;

});